﻿/*************************************************************************
 * R-Tree/R*-Tree 节点
 * 
 * @author lmliang@live.cn
 *************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RStarTree
{
    /// <summary>
    /// R*-Tree
    /// </summary>
    /// <typeparam name="TLeaf">叶子类型</typeparam>
    partial class RStarTree<TLeaf>
    {
        /// <summary>
        /// R-Tree 节点
        /// </summary>
        private class RTreeNode : RTreeBoundingBox
        {
            /// <summary>
            /// 子节点或叶子
            /// </summary>
            public List<RTreeBoundingBox> Items = new List<RTreeBoundingBox>();

            /// <summary>
            /// 是否叶节点
            /// </summary>
            public Boolean IsLeafNode = false;

            /// <summary>
            /// 构造
            /// </summary>
            /// <param name="dimension">维度</param>
            /// <param name="isLeafNode">是否叶节点</param>
            public RTreeNode(Int32 dimension, Boolean isLeafNode)
                : base(dimension)
            {
                IsLeafNode = isLeafNode;
            }

            /// <summary>
            /// 更新包围盒
            /// </summary>
            public void UpdateBoundingBox()
            {
                Reset();
                Items.ForEach(delegate(RTreeBoundingBox bound) { Stretch(bound); });
            }
        }

        /// <summary>
        /// R-Tree 叶子
        /// </summary>
        /// <typeparam name="TLeaf">叶子类型</typeparam>
        private class RTreeLeaf<TLeaf> : RTreeBoundingBox
        {
            /// <summary>
            /// 叶子
            /// </summary>
            public TLeaf Leaf;

            /// <summary>
            /// 构造
            /// </summary>
            /// <param name="dimension">维度</param>
            public RTreeLeaf(TLeaf leaf, RTreeBoundingBox bound)
                : base(bound)
            {
                Leaf = leaf;
            }
        }
    }
}